import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';

import '../../resources/kq_theme_colors.dart';

/// 标签控件
///
/// 圆角边框(实线或虚线) + 文字
class KqTagView extends StatelessWidget {
  /// 文字
  final String text;

  /// 字体大小，默认14
  final double? fontSize;

  /// 内边距
  final EdgeInsets? padding;

  /// 是否虚线，默认false
  final bool dashLine;

  /// 文字颜色，默认黄色
  final Color textColor;

  /// 边框颜色，默认黄色
  final Color borderColor;

  /// 背景颜色，默认透明
  final Color backgroundColor;

  /// 圆角，默认3
  final double? radius;

  const KqTagView(
      {Key? key,
      required this.text,
      this.padding,
      this.dashLine = false,
      this.fontSize,
      this.textColor = KqThemeColors.textYellow,
      this.borderColor = KqThemeColors.textYellow,
      this.backgroundColor = KqThemeColors.bgTransparent,
      this.radius})
      : super(key: key);

  /// 红色，空心
  const KqTagView.redOutline(
      {Key? key,
      required this.text,
      this.padding,
      this.dashLine = false,
      this.fontSize,
      this.textColor = KqThemeColors.textAlarm,
      this.borderColor = KqThemeColors.textAlarm,
      this.backgroundColor = KqThemeColors.bgTransparent,
      this.radius})
      : super(key: key);

  /// 橙色，空心
  const KqTagView.orangeOutline(
      {Key? key,
      required this.text,
      this.padding,
      this.dashLine = false,
      this.fontSize,
      this.textColor = KqThemeColors.textIdle,
      this.borderColor = KqThemeColors.textIdle,
      this.backgroundColor = KqThemeColors.bgTransparent,
      this.radius})
      : super(key: key);

  /// 绿色，空心
  const KqTagView.greenOutline(
      {Key? key,
      required this.text,
      this.padding,
      this.dashLine = false,
      this.fontSize,
      this.textColor = KqThemeColors.textWork,
      this.borderColor = KqThemeColors.textWork,
      this.backgroundColor = KqThemeColors.bgTransparent,
      this.radius})
      : super(key: key);

  /// 蓝色，空心
  const KqTagView.blueOutline(
      {Key? key,
      required this.text,
      this.padding,
      this.dashLine = false,
      this.fontSize,
      this.textColor = KqThemeColors.textLightBlue,
      this.borderColor = KqThemeColors.textLightBlue,
      this.backgroundColor = KqThemeColors.bgTransparent,
      this.radius})
      : super(key: key);

  /// 灰色，空心
  const KqTagView.grayOutline(
      {Key? key,
      required this.text,
      this.padding,
      this.dashLine = false,
      this.fontSize,
      this.textColor = KqThemeColors.textBlack25,
      this.borderColor = KqThemeColors.textBlack25,
      this.backgroundColor = KqThemeColors.bgTransparent,
      this.radius})
      : super(key: key);

  /// 红色，实心
  const KqTagView.redFill(
      {Key? key,
      required this.text,
      this.padding,
      this.dashLine = false,
      this.fontSize,
      this.textColor = KqThemeColors.textWhite,
      this.borderColor = KqThemeColors.textAlarm,
      this.backgroundColor = KqThemeColors.textAlarm,
      this.radius})
      : super(key: key);

  /// 橙色，实心
  const KqTagView.orangeFill(
      {Key? key,
      required this.text,
      this.padding,
      this.dashLine = false,
      this.fontSize,
      this.textColor = KqThemeColors.textWhite,
      this.borderColor = KqThemeColors.textIdle,
      this.backgroundColor = KqThemeColors.textIdle,
      this.radius})
      : super(key: key);

  /// 绿色，实心
  const KqTagView.greenFill(
      {Key? key,
      required this.text,
      this.padding,
      this.dashLine = false,
      this.fontSize,
      this.textColor = KqThemeColors.textWhite,
      this.borderColor = KqThemeColors.textWork,
      this.backgroundColor = KqThemeColors.textWork,
      this.radius})
      : super(key: key);

  /// 蓝色，实心
  const KqTagView.blueFill(
      {Key? key,
      required this.text,
      this.padding,
      this.dashLine = false,
      this.fontSize,
      this.textColor = KqThemeColors.textWhite,
      this.borderColor = KqThemeColors.textLightBlue,
      this.backgroundColor = KqThemeColors.textLightBlue,
      this.radius})
      : super(key: key);

  /// 灰色，实心
  const KqTagView.grayFill(
      {Key? key,
      required this.text,
      this.padding,
      this.dashLine = false,
      this.fontSize,
      this.textColor = KqThemeColors.textWhite,
      this.borderColor = KqThemeColors.textBlack25,
      this.backgroundColor = KqThemeColors.textBlack25,
      this.radius})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return dashLine
        ? DottedBorder(
            borderType: BorderType.RRect,
            strokeWidth: 1,
            padding: const EdgeInsets.all(0.5),
            color: borderColor,
            borderPadding: const EdgeInsets.only(bottom: 0.5),
            radius: Radius.circular(radius ?? 3.r),
            child: ClipRRect(
              borderRadius: BorderRadius.all(Radius.circular(radius ?? 3.r)),
              child: Container(
                color: backgroundColor,
                padding: padding ??
                    EdgeInsets.symmetric(horizontal: 4.r, vertical: 2.r),
                child: Text(
                  text,
                  style:
                      TextStyle(fontSize: fontSize ?? 16.sp, color: textColor),
                ),
              ),
            ),
          )
        : Align(
            alignment: Alignment.center,
            child: Container(
              padding: padding ??
                  EdgeInsets.symmetric(horizontal: 4.r, vertical: 2.r),
              decoration: BoxDecoration(
                  color: backgroundColor,
                  borderRadius:
                      BorderRadius.all(Radius.circular(radius ?? 3.r)),
                  border: Border.all(width: 1, color: borderColor)),
              child: Text(
                text,
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: fontSize ?? 16.sp, color: textColor),
              ),
            ),
          );
  }
}
